<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./vue.js"></script>
</head>

<body>
  <div id="app">
    <h1>当前计数：{{counter}}</h1>
    <!-- <button v-on:click="counter++">+</button> -->
    <!-- v-on语法监听事件 最简单做法 -->
    <!-- <button v-on:click="counter--">-</button> -->
    <button v-on:click="add">+</button>
    <button v-on:click="sub">-</button>
  </div>
  <script src='./vue.js'></script>
  <script>
    const app = new Vue({ //vue内部是对象类型的
      el: '#app', //挂载元素
      data: {
        counter: 0,
      },
      methods: { //可以定义多个方法 也是个对象
        add() {
          //在methods中不要这么写，这里会去找全局的变量，这里会找不到报错
          //counter++; 
          this.counter++; //使用this语法来获取当前对象
          console.log('add被执行');

        },
        sub() {
          this.counter--;
          console.log('sub被执行');

        }
      }
    })
  </script>
</body>

</html>